package com.cljz.makepassenger.ui.holder;

import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.cljz.makepassenger.base.App;
import com.cljz.makepassenger.R;
import com.cljz.makepassenger.model.net.bean.ActivityListBean;
import com.cljz.makepassenger.widget.PicassoRoundTransform;
import com.squareup.picasso.Picasso;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import de.hdodenhof.circleimageview.CircleImageView;

import static com.squareup.picasso.MemoryPolicy.NO_CACHE;
import static com.squareup.picasso.MemoryPolicy.NO_STORE;

/**
 * Created by apple on 2017/4/26.
 */

public class NearByListHolder extends RecyclerView.ViewHolder {


    @BindView(R.id.civ_head_pic)
    CircleImageView civHeadPic;
    @BindView(R.id.tv_nickname)
    TextView tvNickname;
    @BindView(R.id.iv_activity_collect)
    ImageView ivActivityCollect;
    @BindView(R.id.raiv_activity_pic)
    ImageView raivActivityPic;
    @BindView(R.id.iv_hot)
    ImageView ivHot;
    @BindView(R.id.tv_activity_title)
    TextView tvActivityTitle;
    @BindView(R.id.tv_distance)
    TextView tvDistance;
    @BindView(R.id.tv_number)
    TextView tvNumber;
    @BindView(R.id.tv_time)
    TextView tvTime;
    private boolean isFirst = true;
    private int width;
    private int height;

    public NearByListHolder(View itemView) {
        super(itemView);
        ButterKnife.bind(this, itemView);

    }

    public void setData(List<ActivityListBean.DataBean> activityList, int position) {
        final ActivityListBean.DataBean data = activityList.get(position);
        Picasso.with(App.getInstance())
                .load(data.getUser_logo())
                .error(R.mipmap.head_loading)
                .placeholder(R.mipmap.head_loading)
                .into(civHeadPic);
        tvNickname.setText(data.getUser_nickname());
        if ("1".equals(data.getIs_collection())) {
            ivActivityCollect.setImageResource(R.mipmap.nearby_collect_r);
        } else if ("0".equals(data.getIs_collection())) {
            ivActivityCollect.setImageResource(R.mipmap.nearby_collect);
        }

        String tag = data.getImg_path();
        if (!data.getImg_path().equals(raivActivityPic.getTag())) {
            raivActivityPic.setTag(tag);
            Picasso.with(App.getInstance())
                    .load(data.getImg_path())
                    .memoryPolicy(NO_CACHE, NO_STORE)
                    .error(R.mipmap.activity_loading)
                    .placeholder(R.mipmap.activity_loading)
                    .resize(750,450)
                    .centerCrop()
                    .transform(new PicassoRoundTransform())
                    .into(raivActivityPic);
        }

        tvActivityTitle.setText(data.getTitle());
        tvDistance.setText(data.getDistance());
        tvNumber.setText(data.getNumber_join() + "/" + data.getNumber_all());
        tvTime.setText(data.getActivity_time());
    }
}
